﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils
{
    public class MemoryCache
    {
        private static MemoryCache Instance = new MemoryCache();
        static System.Web.Caching.Cache cache
        {
            get
            {
                return System.Web.HttpRuntime.Cache;
            }
        }

        static public MemoryCache GetInstance()
        {
            return Instance;
        }

        public void AddCache(string key, object data)
        {
            cache.Insert(key, data, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0, 0, 0),
                System.Web.Caching.CacheItemPriority.Default, null);
        }

        public void AddCache(string key, object data, int minute)
        {
            cache.Add(key, data, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, minute, 0),
                System.Web.Caching.CacheItemPriority.Default, null);
        }

        public void RemoveChache(string key)
        {
            cache.Remove(key);
        }

        public object GetCache(string key)
        {
            return cache[key];
        }
    }
}
